#include "main/utils.h"
using namespace std;

class Solution {
public:
  int specialArray(vector<int>& nums) {
    // sort(nums.begin(), nums.end(), [&](int a, int b) {
    //     return a > b;
    //     });
    sort(nums.begin(), nums.end(), greater<int>());
    for (int i = 0; i < nums.size(); ++i) {
      if (nums[i] >= i + 1 && (i + 1 == nums.size() || nums[i + 1] < i + 1)) {
        return i + 1;
      }
    }
    return -1;
  }
};

int main() {
  vector<int> nums = {0, 4, 3, 0, 4};
  Solution su;
  cout << su.specialArray(nums) << endl;

  nums = {0, 0};
  cout << su.specialArray(nums) << endl;

  return 0;
}
